<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="24" :xs="24">
                <bar-chart :chart-data="chartData" />
            </el-col>
            <el-col :span="24" :xs="24">
                <el-table v-loading="loading" :data="myClassList" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column :label="$locale('classList.class')" align="center" key="className" prop="className" />
                    <el-table-column :label="$locale('geWudevice.add.Experiment Name')" align="center" key="experimentName" prop="experimentName" />
                    <el-table-column :label="$locale('geWuExperiment.author')" align="center" key="createBy" prop="createBy" />
                    <el-table-column :label="$locale('geWudevice.Creation time')" align="center" prop="createTime" width="160">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.createTime) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$locale('geWuExperiment.classification')" align="center" key="experimentType" prop="experimentType" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span v-for="item in dict.type.experiment_type" :key="item.value">{{ item.value == scope.row.experimentType?item.label:'' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$locale('geWuExperiment.Experimental time')" align="center" key="experimentTime" prop="experimentTime" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span v-for="item in dict.type.experiment_time" :key="item.value">{{ item.value == scope.row.experimentTime?item.label:'' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$locale('geWuExperiment.difficulty')" align="center" key="difficultyLevel" prop="difficultyLevel" width="120">
                        <template slot-scope="scope">
                            <span v-for="item in dict.type.difficulty_level" :key="item.value">{{ item.value == scope.row.difficultyLevel?item.label:'' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable column-key="status" :filters="[{text: $locale('classList.normal'), value: '1'}, {text: $locale('classList.freeze'), value: '0'}]" :filter-method="filterHandler" :label="$locale('geWudevice.add.state')" align="center" key="status" prop="status">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.status == 0?'success':'danger'" effect="dark">
                                {{ scope.row.status == 0?$locale('classList.normal'):$locale('classList.freeze') }}
                            </el-tag>
                        </template>
                    </el-table-column>
                </el-table>

                <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
            </el-col>
        </el-row>
    </div>
</template>

  <script>
import { deleteById, getClassList, list, setStatus } from "@/api/myClass/classList";
import BarChart from '@/views/dashboard/BarChart.vue'
import { getNames } from '@/utils/index'


export default {
    name: "myClass",
    dicts: ['difficulty_level', 'experimental_status'],
    components: { BarChart },
    data () {
        return {
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 用户表格数据
            myClassList: [],
            // 弹出层标题
            title: "",
            loginForm: {
                id: undefined,
                password: undefined
            },
            // 部门树选项
            deptOptions: undefined,
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10
            },
            chartData: [[180, 160, 151, 106, 145, 150, 130], [200, 192, 120, 144, 160, 130, 140]],
        };
    },
    created () {
        this.getList();
    },
    methods: {
        /** 查询用户列表 */
        getList () {
            this.loading = true;
            list(this.queryParams).then(({ data }) => {
                this.myClassList = data.records;
                this.total = data.total;
                this.loading = false;
            });
            // let series = []
            // let data = []
            // getClassList(this.convertArraysToStrings(this.queryParams)).then(({ data }) => {
            //     this.chartData = data.map(item=>{
            //         item['series'].push
            //         let obj = {
            //             name: 'pageA',
            //             type: 'bar',
            //             data: item,
            //             animationDuration
            //         }
            //     });
            // });
        },
        /** 搜索按钮操作 */
        handleQuery () {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        filterHandler (value, row, column) {
            const property = column['property'];
            return row[property] === value;
        },
        /** 重置按钮操作 */
        resetQuery () {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 新增按钮操作 */
        handleAdd () {
            this.$refs.addDeviceList.handleAdd()
        },
        handleSelectionChange (selection) {
            this.ids = selection.map(item => item.id);
        },
        /** 冻结按钮操作 */
        handleFreeze (row) {
            const Ids = row && row.id || this.ids;
            this.$modal.confirm(this.$locale('geWudevice.tip4') + getNames(this.myClassList, Ids, 'className') + this.$locale('geWudevice.tip2')).then(() => {
                if (row && row.id) {
                    setStatus({id:Ids}).then(() => this.getList())
                } else {
                    setStatusByIds({id:Ids}).then(() => this.getList())
                }
            }).then((res) => {
                if (res.code == 200) this.$modal.msgSuccess(this.$locale('geWudevice.tip5'));
            }).catch(() => { });
        },
        /** 修改按钮操作 */
        handleUpdate (row, disabled) {
            this.$refs.addDeviceList.handleUpdate(row, disabled)
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    resetPwd(this.loginForm).then(response => {
                        this.$modal.msgSuccess(this.$locale('geWudevice.add.tip5'));
                        this.handleQuery();
                        this.open = false;
                    });
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete (row) {
            const ids = row.id || this.ids;
            this.$modal.confirm(this.$locale('geWudevice.tip1') + getNames(this.myClassList, ids, 'className') + this.$locale('geWudevice.tip2')).then(function () {
                return deleteById({ id: ids });
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess(this.$locale('geWudevice.tip3'));
            }).catch(() => { });

        },
    }
};
  </script>
